<?php

require_once ("include.php");
require_once ("registereduserobj.php");
$obj = new registereduser();
$obj->applyfromrequest();
if($obj->valid) {
 echo createnew();
} else {
xd($obj->valids);
 echo newaccount();
}

function newaccount() {
 $name = @$_REQUEST['email'];
 $email = @$_REQUEST['userid'];
 $o = <<< STARTTAG
<link href='css/style.css' rel='stylesheet' type='text/css' />
<div class='banner'>
</div>
<script>
function validateform() {
  var p = document.form.f5.value
  var p2 = document.form.pass2.value
  var weak = /^[A-Za-z]\w{6,14}$/;
  var good = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,20}$/;
  document.form.createnew.disabled = true;
  document.form.createnew.style.visibility = 'hidden';
  if (p2 == p && (p.match(weak) || p.match(good))) {
    document.form.createnew.disabled = false;
    document.form.createnew.style.visibility = 'visible';
    document.getElementById('passwordcomment').innerHTML = '';
  } else if (p2 == p) {
    document.getElementById('passwordcomment').innerHTML = 'Password Too weak';
  } else if (p.length > 0) {
    document.getElementById('passwordcomment').innerHTML = "Passwords don't match";
  }
} 
</script>
<div class='welcome'>
<form id=form name=form type=POST action=newaccount.php>
<table>
<tr><td>Full Name</td><td><input type=text name=name value='$name'></td></tr>
<tr><td>Email Address</td><td><input type=text name=f1 value='$email'></td></tr>
<tr><td>Password</td><td><input onKeyUp='validateform()' id=pass1 type=password name=f5 value=''></td><td><div class='passcomment' id=passwordcomment></div><td></tr>
<tr><td>Password (Type again to check)</td><td><input onKeyUp='validateform()' id=pass2 type=password id=newpasswordcheck value=''></td></tr>
<tr><td><input type=submit id=createnew disabled=true style='visibility:hidden;' name=createnew value='Create a new account'></td></tr>
</table>
</form>
STARTTAG;
 return $o;
}

function createnew($name,$password,$email) {
 $o = "<div class='banner'>";
 $o .= "</div>";
 $obj->createblank();
 $o .= "Cool your account is almost ready. You have been sent an email. Don't forget to check your junk folder if you don't get the email.";
 $obj->addline();
 $confirmcode = $obj->setnewuser($name,$email,$password);
 $sql = "delete from registereduser where name = '$email'";
 $obj->writedb();
 $message = "In order to activate your account, click on the following link\n";
 $message .= "http://liftmate.com/confirmaccount.php?id=".$confirmcode;
 $email = "antonylawler@gmail.com"; // Test purposes only
 mail($email,'Your account with liftmate is almost ready',$message);
 return $o;
}

?>

